package com.android.picotts.ui.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewParent;
import android.widget.TextView;

public class SelectTextView extends TextView implements TextView.OnClickListener{

    private OnClickListener mListener;
    
    public SelectTextView(Context context) {
        super(context);
    }
    
    public SelectTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    
    public SelectTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
    
    @Override
    public void setOnClickListener(OnClickListener l) {
        mListener = l;
        super.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if(mListener != null) {
            setSelected(!isSelected());
            ViewParent parent = getParent();
            if(parent instanceof SelectLinelayout) {
                SelectLinelayout one = (SelectLinelayout)parent;
                one.update(v.getId());
            }
            mListener.onClick(v);
        }
    }
}
